﻿<template>
  <div class="app-container">
    <div v-if="count" class="tableTitle">
      <span v-if="count.play_count">播放中:{{ count.play_count }}</span>
      <span v-else>播放中:0</span>
      <span v-if="count.check_count">审核中:{{ count.check_count }}</span>
      <span v-else>审核中:0</span>
      <span v-if="count.rule_await">待发布:{{ count.month_count }}</span>
      <span v-else>待发布:0</span>
      <span v-if="count.play_rule_check">待审核:{{ count.play_rule_check }}</span>
      <span v-else>待审核:0</span>
      <span v-if="count.play_over">已结束:{{ count.play_over }}</span>
      <span v-else>已结束:0</span>
    </div>
    <div class="filter-title">
      <el-form label-position="right" label-width="95px">
        <el-form-item :label="$t('videoData.videoName')+' :'">
          <el-input
            v-model="listQuery.video_name"
            style="width: 150px"
            class="filter-item"
            :placeholder="$t('videoData.videoName')"
            @keyup.enter.native="handleFilter"
          ></el-input>
        </el-form-item>
        <el-form-item :label="$t('videoData.videoStatus')+' :'">
          <el-select
            v-model="listQuery.status"
            clearable
            style="width: 150px"
            class="filter-item"
            :placeholder="$t('videoData.videoStatus')"
          >
            <el-option
              v-for="item in statusOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-button
          style="margin-left: 20px;"
          class="filter-item"
          type="primary"
          icon="el-icon-search"
          @click="handleFilter"
        >{{ $t('table.search') }}</el-button>
        <el-button
          style="margin-left: 10px"
          class="filter-item"
          type="primary"
          @click="handleRefresh"
        >{{ $t('table.refresh') }}</el-button>
      </el-form>
    </div>
    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      element-loading-text="拼命加载中"
      element-loading-spinner="el-icon-loading"
      element-loading-background="rgba(255,255,255,0.2)"
      border
      fit
      highlight-current-row
      style="width: 100%min-height:1000px"
    >
      <el-table-column fixed="left" align="center" :label="$t('table.id')" width="65">
        <template slot-scope="scope">
          <span>{{ (listQuery.page-1)*listQuery.limit+scope.$index+1 }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip :label="$t('videoData.videoName')">
        <template slot-scope="scope">
          <span>{{ scope.row.video_name }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip :label="$t('videoData.videoStatus')">
        <template slot-scope="scope">
          <span>{{ stateEstimation(scope.row.video_status) }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip :label="$t('videoData.playCount')">
        <template slot-scope="scope">
          <span>{{ scope.row.play_count }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip :label="$t('videoData.viewCount')">
        <template slot-scope="scope">
          <span>{{ scope.row.view_count }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip :label="$t('videoData.couponGetCount')">
        <template slot-scope="scope">
          <span>{{ scope.row.coupon_get_count }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip :label="$t('videoData.couponUseCount')">
        <template slot-scope="scope">
          <span>{{ scope.row.coupon_use_count }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip :label="$t('videoData.orderCount')">
        <template slot-scope="scope">
          <span>{{ scope.row.order_count }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip :label="$t('videoData.orderPayCount')">
        <template slot-scope="scope">
          <span>{{ scope.row.order_pay_count }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip :label="$t('videoData.moneySum')">
        <template slot-scope="scope">
          <span>{{ scope.row.money_sum }}</span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        align="center"
        :label="$t('table.actions')"
        :width="operWidth"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            @click="handleRead(scope.row)"
          >{{ $t('table.read') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination-container">
      <el-pagination
        background
        :current-page="listQuery.page"
        :page-sizes="[10,20,30,50]"
        :page-size="listQuery.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
export default {
  name: "VideoPlayData",
  data() {
    return {
      showSearchItem: false,
      loading: false,
      tableKey: 0,
      list: null,
      total: null,
      count: undefined,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        time: "",
        status: undefined,
        video_name: ""
      },
      dialogStatus: "",
      textMap: {
        update: "更新",
        create: "添加",
        review: "审核",
        read: "查看"
      },
      statusOptions: [
        {
          value: 1,
          label: "视频审核中"
        },
        {
          value: 2,
          label: "规则待添加"
        },
        {
          value: 3,
          label: "规则待审核"
        },
        {
          value: 4,
          label: "发布中"
        },
        {
          value: 5,
          label: "发布中[规则审核]"
        },
        {
          value: 6,
          label: "发布结束"
        }
      ]
    };
  },
  computed: {
    operWidth: function() {
      return this.opreaterItem * 80 + "px";
    }
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.listLoading = true;
      const data = {
        rows: this.listQuery.limit,
        page: this.listQuery.page
      };
      if (this.listQuery.video_name) {
        data["video_name"] = this.listQuery.video_name;
      }
      if (this.listQuery.status) {
        data["status"] = this.listQuery.status;
      }
      const adMasterIndexPath = {
        // 年月播放报表列表
        company: "STQ",
        api: "pc_VideoPlayData_list",
        version: "1.0",
        data: data
      };
      this.socketApi.sendSock(JSON.stringify(adMasterIndexPath), res => {
        if (res) {
          if (res !== '{"type":"ping"}') {
            const resj = JSON.parse(res);
            if (resj.code === -1) {
              this.$message.error(resj.message);
            } else {
              this.total = resj.count;
              this.list = resj.data.data;
              this.count = {
                check_count: resj.data.check_count,
                play_count: resj.data.play_count,
                play_over: resj.data.play_over,
                play_rule_check: resj.data.play_rule_check,
                rule_await: resj.data.rule_await,
                rule_await_check: resj.data.rule_await_check,
                sum: resj.data.sum
              };
            }
          }
          this.listLoading = false;
        }
      });
    },
    handleFilter() {
      this.listQuery.page = 1;
      this.getList();
    },
    handleSizeChange(val) {
      this.listQuery.limit = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.getList();
    },
    handleRefresh() {
      this.listQuery = {
        page: 1,
        limit: 20,
        time: "",
        status: undefined,
        video_name: ""
      };
      this.getList();
    },
    stateEstimation(status) {
      switch (parseInt(status)) {
        case 1:
          return "视频审核中";
        case 2:
          return "规则待添加";
        case 3:
          return "规则待审核";
        case 4:
          return "发布中";
        case 5:
          return "发布中[规则审核]";
        case 6:
          return "发布结束";
        default:
          return status;
      }
    },
    handleRead(row) {
      this.$router.push({
        name: "videoPlayData/index",
        query: {
          id: row.video_id,
          name: row.rule_name,
          status: row.video_status
        }
      });
    }
  }
};
</script>
